package com.noodles.mall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.noodles.mall.entity.ItemImage;
import com.noodles.mall.mapper.ItemImageMapper;
import com.noodles.mall.service.ItemImageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/** 商品轮播图 **/
@Service
public class ItemImageServiceImpl extends ServiceImpl<ItemImageMapper, ItemImage> implements ItemImageService {

    /** 增加 **/
    public ItemImage insert(Integer itemId,String imageUrl){
        ItemImage itemImage=new ItemImage();
        itemImage.setItemId(itemId);
        itemImage.setImageUrl(imageUrl);
        return super.save(itemImage) ? selectOne(itemImage.getImageUrl()) : null;
    }

    /** 删除 **/
    public ItemImage delete(Integer id){
        ItemImage itemImage=super.getById(id);
        return super.removeById(id) ? itemImage : null;
    }

    /** 查询单个: imageUrl **/
    public ItemImage selectOne(String imageUrl){
        return super.getOne(new QueryWrapper<ItemImage>().lambda()
                .eq(ItemImage::getImageUrl,imageUrl)
        );
    }

    /** 查询列表: 商品id  **/
    public List<ItemImage> selectList(Integer itemId){
        return super.list(new QueryWrapper<ItemImage>().lambda()
                .eq(ItemImage::getItemId,itemId)
        );
    }

}
